const initialState = {
    list:[],
    num:1,
    activeIndex:0,
    data:[]
}
export default (state = initialState, { type, payload }) => {
  let {list, activeIndex,data}=state
  switch (type) {
  case "ADD_NUM":
    return { ...state, ...payload }

    case "SET_LIST":
      list=payload
      return {
        ...state,
        list
       
      }
      case "SET_ACTIVE":
        activeIndex=payload
        return{
          ...state,
          activeIndex
        }
    
    case "SET_DATA":
      data=payload
      return {
        ...state,
        data
      }
      case "REMOCE_DATA":
        data=data.filter((item)=>item.id!==payload)
        return {
          ...state,
          data
        }
      case "ADD_DATA":
        data.unshift(payload)
        return{
          ...state,
          data:[...data]
        }


  default:
    return state
  }
}
